package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//过滤器
//@WebFilter("/1010/democ")
public class FirstFilter implements Filter {
    public FirstFilter() {
        System.out.println("FirstFilter被new了");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("FirstFilter被初始化啦");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("我要对你进行检查");
        int num = (int)(Math.random()*100);
        if (num%2==0){
            System.out.println("你符合要求！"+num);
            //放行
            filterChain.doFilter(servletRequest,servletResponse);
            System.out.println("你又来了啊！");
        }else {
            System.out.println("你不符合要求，你不能进去！");
        }
    }

    @Override
    public void destroy() {
        System.out.println("FirstFilter被销毁啦");
    }
}
